<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/6/5
 * Time: 16:02
 */

namespace common\validate;
use api\lib\exception\ParamErrorHttpException;
use yii\base\ErrorException;
use yii\base\Model;
use yii\web\NotFoundHttpException;
use yii\web\Request;
use Yii;

class BaseValidate extends Model
{
    //验证方法
    public function goCheck()
    {
        //获取http传入的参数
        $result = new Request();

        //如果是get方式,就用get获取
        if($result->isGet){
            $param = $result->getQueryParams();
        }else{
            $param = $result->getBodyParams();
        }

        //参数赋值和校验
        $this->attributes = $param;
        $result = $this->validate();

        //设置统一的参数校验层
        if(!$result){
            return false;
        }else{
            return true;
        }
    }

}